%Secante recibe los dos valores iniciales para x, la funcion, la tolerancia
%y el numero de iteraciones deseadas.
function b = secante(x0,x1,foo,tol,iter)
xnm1 = x0;
xn= x1;
f = inline (foo);
fxnm1 = f (xnm1); % fxn-1
fxn = f (xn);
error = abs ( fxn - fxnm1  );
b = [xnm1 fxnm1 NaN;xn fxn error];
cont = 1;
while (error > tol && ~(fxnm1==0) &&  ~(fxn==0) && ~((fxn - fxnm1)==0) && cont <= iter)
    gx = xn - ((fxn * ( xn - xnm1 )) / (fxn - fxnm1));
    xnm1 = xn;
    xn = gx ;
    fxnm1  = fxn;
    fxn =  f (xn);
    error = abs ( xn - xnm1 );
    b = [b;xn fxn error];
    iter = iter + 1;
end
fp = figure ('Position',[100 100 752 350]);
t = uitable ('Parent',fp,'Position',[100 100 652 350]);
set (t,'Data',b);
set (t,'ColumnName',{'x','f(x)','Error'});


end
